% rts file cmpression
% latest date 6.1.2003
% Reference: 

[fid,er] = getbfile('*.rts');
[TS,fid] = rts_in(fid);
%p = max(L)-min(L);
%manoj = zeros([1 p+1]);
%for i =1 :o,
%   manoj(h(i)-s) = manoj(h(i)-s) +1;
%end;
%plot(manoj);
%sum(manoj(9400:9600))/sum(manoj);
fclose(fid);

s = length(TS.matrix);
ll = 128;
blk = (s/ll)-1;
%blk = 10;
st = 1;
en = ll;
FirstData = TS.matrix(1,:);
fid = fopen('e:\manoj\data\test','wb');
[count] = fwrite(fid,FirstData,'int16');
for i = 1:blk,
   diff = TS.matrix(st:en,:)-TS.matrix(st+1:en+1,:);
   mn = min(diff);
   mx = max(diff);
   for j = 1:5,
      if mx(j) > 128 | mx(j) < -128,
         [count] = fwrite(fid,2,'int8');
         [count] = fwrite(fid,diff(:,j),'int16');
      else,
         [count] = fwrite(fid,1,'int8');
         [count] = fwrite(fid,diff(:,j),'int8');
      end;
      
   end;
   st = st+ll;
   en = en+ll;
   
end;

fclose(fid);


  

